package leetcode.editor.cn;

public class List {
    public static void main(String[] args) {
        List list = new List();
        list.solution();
    }
    class ListNode {
        int val;
        ListNode next;
        ListNode(int x) { val = x; }
    }

    // 输入一个数组，转换为一条单链表
    ListNode createLinkedList(int[] arr) {
        if (arr == null || arr.length == 0) {
            return null;
        }
        ListNode head = new ListNode(arr[0]);
        ListNode cur = head;
        for (int i = 1; i < arr.length; i++) {
            cur.next = new ListNode(arr[i]);
            cur = cur.next;
        }
        return head;
    }
    void solution(){
        ListNode head = createLinkedList(new int[]{1, 2, 4, 5});
        for (ListNode p = head; p != null; p = p.next){
            System.out.println(p.val);
        }
    }
}
